package com.maple.controller;

import com.maple.pojo.User;
import com.maple.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@Controller
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/login")
    public String login(){
        return "login";
    }

    @RequestMapping({"/submin","/submin{username}"})
    public String submin( String username,  String password, Model model,HttpSession session){
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        boolean flag = userService.login(user);
        if(flag==true){
            session.setAttribute("loginUser",username);
            return "index";
        }else {
            model.addAttribute("msg","用户名或者密码错误!");
            return "login";
        }
    }

    @RequestMapping("/zhuce")
    public String zhuce(){
        return "zhuce";
    }

    @RequestMapping("/end")
    public String end(@RequestParam("username") String username,@RequestParam("password") String password,Model model){

        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        boolean flag = userService.zhuCe(user);
        if(flag==true){
            return "login";
        }else{
            model.addAttribute("msg","注册失败!");
            return "zhuce";
        }
    }

}
